object
object is a type just like string is a type.
However, objects are effectively data structures since they store, manage and modify data - specifically key-value pairs.
info
Objects are quite important to learn and understand as they are the top level, the pinnacle type.
Almost everything is derived from the object object in Hedgehog Script.
Let's discuss the constructor for object - which creates objects:
If the input is
nullorundefinedyou will get an emptyobject. If the argument is anobjectitself it will return itself.Otherwise, the
constructorwill return anobjectof a type that corresponds to the given argument.
Let's view an example of creating objects:
info
There is no direct method to delete object properties like Map (which has Map.delete()) for example.
Rather, one must use the delete operator: delete Object.property;
There are quite a few methods, static or instance, for object. Let's point out some of them:
Object()- theconstructor, takes the input and makes it an object.(
static)Object.entries()- returns an array with all [key, value] pairs of a given object.(
static)Object.seal()- prevents other code from deleting properties of an object.(
instance)Object.hasOwnProperty()- returnstrueorfalsebased on whether the object has the direct property.(
instance)Object.toString()- returns aStringrepresentation of the object.
Objects can be quite a complex topic. They are fundamental and have a long list of methods and details.
tip
If one is curious to learn more, check out Objects for more info.